#include "./ctrl.h"
#include "../device/gpio.h"
#include "../rtos/rtos.h"

namespace driver::ctrl {

using namespace device;

using COMPR = PD<4>;
using ELOCK = PD<3>;
using BEEP = PC<0>;
using LED0 = PE<10>;
using LED1 = PE<11>;
using LED2 = PE<12>;

void init() {
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN |   
        RCC_AHB1ENR_GPIOCEN |
        RCC_AHB1ENR_GPIOEEN;
    ConfigOutput<COMPR, ELOCK, LED0, LED1, LED2>();
    ConfigOD<BEEP>();
    ELOCK::Set();

    compr_off();
    beep_off();
}

void compr_on() {
    COMPR::Clr();
}

void compr_off() {
    COMPR::Set();
}

void beep_on() {
    BEEP::Clr();
}

void beep_off() {
    BEEP::Set();
}

void elock_open() {
    ELOCK::Clr();
    osDelay(100);
    ELOCK::Set();
}

void led_blink() {
    LED0::Set();
    LED1::Set();
    LED2::Set();
    osDelay(100);
    LED0::Clr();
    LED1::Clr();
    LED2::Clr();
    osDelay(100);
}

void led_toggle() {
    LED0::Toggle();
    LED1::Toggle();
    LED2::Toggle();
}

}

